﻿using System;
using System.Collections.Generic;
using System.Text;


using System.Data;
using System.Data.SqlClient;
using EShop.Model;
using EShop.Common;

namespace EShop.DAL
{
    public class StockInDAL : BaseDAL
    {
        /// <summary>
        /// 添加入库信息
        /// JF
        /// 2011-09-23
        /// </summary>
        /// <param name="oStockIn"></param>
        /// <returns></returns>
        public bool AppendStockIn(StockIn oStockIn)
        {
            string strUSP = "USP_StockIn_Append";
            try
            {
                SqlParameter[] parameter = {
                                           new SqlParameter("@Barcode",SqlDbType.VarChar,30),
                                           new SqlParameter("@StockInNum",SqlDbType.Int),
                                           new SqlParameter("@UnitPrice",SqlDbType.Money),
                                           new SqlParameter("@TotalPrice",SqlDbType.Money),
                                           new SqlParameter("@OverTime",SqlDbType.DateTime)
                                       };
                parameter[0].Value = oStockIn.Barcode;
                parameter[1].Value = oStockIn.StockInNum;
                parameter[2].Value = oStockIn.UnitPrice;
                parameter[3].Value = oStockIn.TotalPrice;
                parameter[4].Value = oStockIn.OverTime;
                if (DbHelper.ExecuteNonQuerySQL(strUSP, CommandType.StoredProcedure, parameter) > 0)
                    return true;
                else return false;
            }
            catch (Exception ex)
            {
                log.Write((string.Format("USP: {0}, \r\n ex : {1}", strUSP, ex.Message)));
                throw;
            }
        }

        /// <summary>
        /// 获取指定Barcode的商品信息。
        /// JF
        /// 2011-09-23
        /// </summary>
        /// <param name="strBarcode">Barcode</param>
        /// <returns></returns>
        public DataTable GetMerchandiseInfo(string strBarcode)
        {
            string strUSP = "USP_Merchandise_BasicInfo_GetAllList";
            try
            {
                SqlParameter parameter = new SqlParameter("@Barcode", SqlDbType.VarChar, 30);
                parameter.Value = strBarcode;
                return DbHelper.ExecuteDataSetSQL(strUSP, CommandType.StoredProcedure, parameter).Tables[0];
            }
            catch (Exception ex)
            {
                log.Write((string.Format("USP: {0}, \r\n ex : {1}", strUSP, ex.Message)));
                throw;
            }
        }


        /// <summary>
        /// 取得库存数量,上架数量
        /// </summary>
        /// <returns></returns>
        public DataTable GetStockExamineList()
        {
            string strUSP = "USP_GetStockExamineList";
            try
            {
                return DbHelper.ExecuteDataSetSQL(strUSP, CommandType.StoredProcedure).Tables[0];
            }
            catch (Exception ex)
            {
                log.Write((string.Format("USP: {0}, \r\n ex : {1}", strUSP, ex.Message)));
                throw;
            }
        }

        /// <summary>
        /// 取得指定商品的库存数量,上架数量
        /// </summary>
        /// <param name="strBarCode"></param>
        /// <returns></returns>
        public DataTable GetStockExamineList(string strBarCode)
        {
            string strUSP = "USP_GetStockExamineList";
            try
            {
                SqlParameter[] para = { new SqlParameter("@BarCode", strBarCode) };
                return DbHelper.ExecuteDataSetSQL(strUSP, CommandType.StoredProcedure, para).Tables[0];
            }
            catch (Exception ex)
            {
                log.Write((string.Format("USP: {0}, \r\n ex : {1}", strUSP, ex.Message)));
                throw;
            }
        }
    }
}